# For some reason next lines produces an error:
# 'Running with gitlab-runner 13.12.0 (7a6612da)
#  on DinD linux abuPZkTg
#Preparing the "docker" executor 00:05
#Using Docker executor with image fedora:build ...
#Pulling docker image fedora:build ...
#WARNING: Failed to pull image with policy "always": Error response from daemon: manifest for fedora:build not found: manifest unknown: manifest unknown (manager.go:205:3s)
#ERROR: Job failed (system failure): failed to pull image "fedora:build" with specified policies [always]: Error response from daemon: manifest for fedora:build not found: manifest unknown: manifest unknown (manager.go:205:3s)'
# To escape this, every target uses hardcoded URL, not an IMG variable usage
#variables:
#  IMG: registry.gitlab.com/docker-images10/debian-plus-build-deps
##    IMG: blacknote.site:5050/restracer/debian-plus-build-deps
##blacknote.site resolves as white IP address inside DinD, so skipped

debian-build-debug:
  image: registry.gitlab.com/docker-images10/debian-plus-build-deps:build
  stage: build
  tags:
    - docker
  script:
    - NPROC=$(nproc)
    - echo "Using '$NPROC' processes to build source..."
    - make debug -j$NPROC
  rules:
    - if: '$CI_COMMIT_REF_NAME =~ $CI_DEFAULT_BRANCH'
      when: always
    - if: '$CI_COMMIT_REF_NAME =~ /^[0-9]\.[A-F]$/'
      when: always
    - if: '$CI_COMMIT_REF_NAME =~ /^[0-9]+\-/'
      when: manual
      allow_failure: true

debian-build-release:
  image: registry.gitlab.com/docker-images10/debian-plus-build-deps:build
  stage: build
  tags:
    - docker
  script:
    - NPROC=$(nproc)
    - echo "Using '$NPROC' processes to build source..."
    - make release -j$NPROC
    - make install
  artifacts:
    paths:
      - src/artlibgen/src/artlibgen
      - src/artrepgen/artrepgen
      - src/artlibgen/templates/
  cache:
    paths:
      - "src/artrepgen/*.o"
      - "src/libs/libtplreader/*.o"
      - "src/artlibgen/src/*.o"
  rules:
    - if: '$CI_COMMIT_REF_NAME =~ $CI_DEFAULT_BRANCH'
      when: always
    - if: '$CI_COMMIT_REF_NAME =~ /^[0-9]\.[A-F]$/'
      when: always
    - if: '$CI_COMMIT_REF_NAME =~ /^[0-9]+\-/'
      when: manual
      allow_failure: true

debian-test-file:
  image: registry.gitlab.com/docker-images10/debian-plus-build-deps:test-file
  stage: test
  tags:
    - docker
  script:
    - make install
    - cd regressions/features && make tracefile-method
  dependencies:
    - debian-build-release
  rules:
    - if: '$CI_COMMIT_REF_NAME =~ $CI_DEFAULT_BRANCH'
      when: always
    - if: '$CI_COMMIT_REF_NAME =~ /^[0-9]\.[A-F]$/'
      when: always
    - if: '$CI_COMMIT_REF_NAME =~ /^[0-9]+\-/'
      when: manual
      allow_failure: true

debian-test-networked:
  image: registry.gitlab.com/docker-images10/debian-plus-build-deps:test-netw
  stage: test
  tags:
    - docker
  script:
    - make install
    - cd regressions/features && make networked-method
  dependencies:
    - debian-build-release
  rules:
    - if: '$CI_COMMIT_REF_NAME =~ $CI_DEFAULT_BRANCH'
      when: always
    - if: '$CI_COMMIT_REF_NAME =~ /^[0-9]\.[A-F]$/'
      when: always
    - if: '$CI_COMMIT_REF_NAME =~ /^[0-9]+\-/'
      when: manual
      allow_failure: true
